﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using MedicService.Domain;
using MedicService.Domain.Directory;
using MedicService.Server.Factory.Generic;

namespace MedicService.Server.Factory {
    public class ComissionFactory : EntityFactory<Comission> {
        public ComissionFactory() : base("Comission", "title") { }

        protected override Comission CreateEntity() {
            return new Comission();
        }

        protected override string GetInsertQuery(Comission entity) {
            string q = "INSERT INTO [Comission]" +
                       " ([organisation]" +
                       " ,[head]" +
                       " ,[job]" +
                       " ,[title]" +
                       " ,[chairman]" +
                       " ,[secretary]) " +
                       " VALUES " +
                       " (" + Nullable(entity.Organisation) +
                       " ," + Nullable(entity.Head) +
                       " ," + Nullable(entity.Job) +
                       " ," + Nullable(entity.Title) +
                       " ," + Nullable(entity.Chairman) +
                       " ," + Nullable(entity.Secretary) + ");" +
                       " ";
            return q;
        }

        protected override string GetUpdateQuery(Comission entity) {
            string q = "UPDATE [Comission] "
                    + " SET [organisation] = " + Nullable(entity.Organisation)
                    + " ,[head] = " + Nullable(entity.Head)
                    + " ,[job] = " + Nullable(entity.Job)
                    + " ,[title] = " + Nullable(entity.Title)
                    + " ,[chairman] = " + Nullable(entity.Chairman)
                    + " ,[secretary] = " + Nullable(entity.Secretary)
                    + " WHERE id=" + entity.Id;
            return q;
        }

        protected override void FillEntity(Comission entity, DataRow myDataRow) {
            base.FillEntity(entity, myDataRow);
            entity.Organisation = myDataRow["organisation"] as string;
            entity.Head = myDataRow["head"] as string;
            entity.Job = myDataRow["job"] as string;
            entity.Title = myDataRow["title"] as string;
            entity.Chairman = myDataRow["chairman"] as string;
            entity.Secretary = myDataRow["secretary"] as string;
        }
    }
}